#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
int main(int argc, char **argv)
{
    int fd;
    int ret;
    int press_cnt[1];
    int led_no=1;
    int led=0;
    fd = open("/dev/buttons", 0);
    if (fd < 0) {
        perror("open err!\n");
        exit(1);
    }
    while(1){
        ret = read(fd,press_cnt,sizeof(press_cnt));
        if (ret< 0) {
            perror("read err!\n");
            exit(1);
        }
        printf("read 1 ok,%d\n",press_cnt[0]);
        if(press_cnt[0]==1){
            system("/etc/reset_ip.c");//调用/etc/reset_ip.c脚本，实现IP恢复出厂设置。
            ioctl(fd,0,led_no);
        }
        ret = read(fd,press_cnt,sizeof(press_cnt));
        if (ret< 0) {
            perror("read err!\n");
            exit(1);
        }
        printf("read 2 ok,%d\n",press_cnt[0]);
        if(press_cnt[0]==1){
            system("/etc/reset_ip.c");
            ioctl(fd,1,led_no);
        }
    }
}


脚本：/etc/reset_ip.c

#!/bin/sh
cat /etc/net0.conf > /etc/net.conf

cat /etc/nettype0.conf > /etc/nettype.conf

cat /etc/wifi0.conf > /etc/wifi.conf

cat /etc/wpa_supplicant0.conf > /etc/wpa_supplicant.conf


